const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: './src/index.js',
  context: process.cwd(),
  mode: 'development',

  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'monitor.js'
  },

  devServer: {
    contentBase: path.resolve(__dirname, 'dist'),
    before(router) {
      router.get('/success', function (req, res) {
        res.json({id: 1});
      });

      router.get('/error', function (req, res) {
        res.sendStatus(500);
      });
    }
  },

  plugins: [
    new HtmlWebpackPlugin({
      // inject: 'head',
      // template: './src/index.html',
      // scriptLoading: 'blocking',

      //我们想生成的script放在link上面
      //并且是sync加载的
      //以确保在资源加载之前,我们的监控脚本就已经注册运行了
      //,以便我们能监控到资源的加载情况
      inject: false,
      template: './src/index.ejs',
      scripts: [
        'http://example.com/somescript.js',
        {
          src: 'monitor.js'
        }
      ],
    })
  ]
}
